<template>
  <div>
    <el-button type="success" style="float: left" @click="add">添加</el-button>
    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column label="编号" width="120">
        <template slot-scope="scope">{{ scope.row.UserTypeID }}</template>
      </el-table-column>
      <el-table-column prop="UserTypeName" label="职位" width="120">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope"
          ><el-button type="primary">权限分配</el-button>

          <el-button type="danger" @click="del(scope.row.UserTypeID)"
            >删除</el-button
          >
           <el-button type="danger" @click="upd(scope.row.UserTypeID)"
            >修改</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="添加职位" :visible.sync="RoleAdd">
      <role-add  @add-ok="addok"></role-add>
    </el-dialog>
    <el-dialog title="修改职位" :visible.sync="RoleUpd">
      <role-upd :id="id" @add-ok="addok"></role-upd>
    </el-dialog>
  </div>
</template>
<script>
import RoleAdd from "./RoleAdd.vue";
import RoleUpd from "./RoleUpd.vue";
import axios from "@/util/axios.js";
export default {
  components: {
    RoleAdd,RoleUpd
  },
  data() {
    return {
      tableData: [],
      RoleAdd: false,
      RoleUpd:false,
      id:""

    };
  },
  methods: {
    upd(id){
        
        this.id=id;
        this.RoleUpd=true;
    },
    del(id) {
      axios.put("api/UserTypes/Delete?id=" + id).then((res) => {
        this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            if (res.data > 0) {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.GettableData();
            }
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除",
            });
          });
      });
    },
    add() {
      this.RoleAdd = true;
    },
    addok() {
      this.RoleAdd = false;
      this.$message("添加成功");
      this.GettableData();
    },
    GettableData() {
      axios.get("api/UserTypes/GetUserTypes").then((res) => {
        this.tableData = res.data;
      });
    },
  },
  created() {
    this.GettableData();
    this.id="";
  },
};
</script>
<style>
</style>